#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
}
const int N = 8e5+10;
struct node{
	int u,v,w;
}a[N];
int n,cur,ans;
int hed[N],nex[N<<1],to[N<<1],w[N<<1],cnt[2][30];
void add(int u,int v,int c){
	nex[++cur]=hed[u],hed[u]=cur,to[cur]=v,w[cur]=c;
	nex[++cur]=hed[v],hed[v]=cur,to[cur]=u,w[cur]=c;
}
void dfs1(int x,int y,int fa){
	for(int i=hed[x];i;i=nex[i])
		if(to[i]^fa) ans+=min(y,w[i]),dfs1(to[i],min(y,w[i]),x);
}
void dfs2(int x,int y,int fa,int op){
	for(int i=hed[x];i;i=nex[i])
		if(to[i]^fa) cnt[op][min(y,w[i])]++,dfs2(to[i],min(y,w[i]),x,op);
}
void solve(){
	for(int i = 1;i<n;i++){
		int res=0;
		memset(cnt,0,sizeof(cnt));
		dfs2(a[i].u,a[i].w,a[i].v,0);
		dfs2(a[i].v,a[i].w,a[i].u,1);
		for(int j = 1;j<=a[i].w;j++){
			for(int k = 1;k<=a[i].w;k++)
				res+=min(j,k)*cnt[0][j]*cnt[1][k];
			res+=j*(cnt[0][j]+cnt[1][j]);
		}
		write(ans-res-a[i].w),putchar('\n');
	}
}
signed main(){
	freopen("tatooine.in","r",stdin);
	freopen("tatooine.out","w",stdout);
	n = read();
	for(int i = 1;i<n;i++) a[i] = (node){read(),read(),read()},add(a[i].u,a[i].v,a[i].w);
	for(int i = 1;i<=n;i++) dfs1(i,20,0);ans>>=1,solve();
	return 0;
}

